using System.Web;
using System.Web.Mvc;
using Blog.Core.Entities;

namespace Blog.Presentation.UIHelpers
{
    public class UrlExtensions
    {
        public static string GetAppRoot()
        {
            var url = HttpContext.Current.Request.Url;
            var relativePath = HttpContext.Current.Request.ApplicationPath;

            if (relativePath.EndsWith("/") == false)
                relativePath += "/";

            var port = (url.Port == 80) ? "" : ":" + url.Port;
            return string.Format("{0}://{1}{2}{3}", url.Scheme, url.Host, port, relativePath);
        }

        public static string LinkToArticle(Article article)
        {
            return string.Format("http://scaparel.com/Archive/{0}", UrlEncoder.ToFriendlyUrl(article.Title));
        }
    }
}